/*
 * @Date: 2024-04-22 13:21:18
 * @LastEditors: lyx
 * @LastEditTime: 2024-04-23 13:14:13
 * @FilePath: \taro-template3\src\packageA\components\ChatParaModelCalculate\index.tsx
 * @Description:
 */
import React, { memo, useContext } from "react";
import { Tag } from "@nutui/nutui-react";
import useSequentialLoader, {
  LoaderContext,
} from "@/utils/hooks/useSequentialLoader";
import { ChatLoadText, ChatLoadMd, ChatLoadTable } from "../ChatLoadDom";
import "./index.less";

export interface ParaModelDataType {
  // beforeAnalysisContent: string;
  // analysisIndexList: any[],
  // afterAnalysisContent: string;
  beforeCalAnalysisContent: string;
  list: any[];
  afterCalAnalysisContent: string;
  analysisReportResult: string;
  createTime: string;
}

interface IProps {
  data: ParaModelDataType;
  loading?: boolean;
  onRender?: (isForce?: boolean) => void;
  onLoad?: () => void;
}

const ChatParaModelCalculate: React.FC<IProps> = ({
  loading,
  onRender,
  onLoad,
}) => {
  // Component State
  const { effectData } = useContext(LoaderContext);

  const columns5 = [
    {
      title: "序号",
      key: "index",
      render: (record: any, index: number) => {
        return index + 1;
      },
    },
    {
      title: "操作参数",
      dataIndex: "operationParameter",
      key: "operationParameter",
      render: (record: any) => {
        return record?.operationParameter ?? "--";
      },
    },
    {
      title: "仪表位号",
      dataIndex: "tagName",
      key: "tagName",
      render: (record: any) => {
        return record?.tagName ?? "--";
      },
    },
    {
      title: "单位",
      dataIndex: "unit",
      key: "unit",
      render: (record: any) => {
        return record?.unit ?? "--";
      },
    },
    {
      title: "正常操作范围",
      dataIndex: "normalOperationRange",
      key: "normalOperationRange",
      render: (record: any) => {
        return record?.normalOperationRange ?? "--";
      },
    },
    {
      title: "优化设定值",
      dataIndex: "optValue",
      key: "optValue",
      render: (record: any) => {
        return record?.optValue ?? "--";
      },
    },
    // {
    //   title: "指标上限",
    //   dataIndex: "upperIndex",
    //   key: "upperIndex",
    //   render: (text: any) => {
    //     return text ? text : "--";
    //   },
    // },
    // {
    //   title: "指标下限",
    //   dataIndex: "lowIndex",
    //   key: "lowIndex",
    //   render: (text: any) => {
    //     return text ? text : "--";
    //   },
    // },
    {
      title: "相关系数",
      dataIndex: "weight",
      key: "weight",
      render: (record: any) => {
        return record?.weight ?? "--";
      },
    },
    {
      title: "是否瓶颈",
      dataIndex: "bottleneck",
      key: "bottleneck",
      render: (record: any, index: any) => {
        return record?.bottleneck ? (
          <Tag color="#E5AF2A">是</Tag>
        ) : (
          <Tag>否</Tag>
        );
      },
    },
  ];
  // Component Effect
  const loadedComponents = useSequentialLoader(
    [
      // {
      //     component: ChatLoadText,
      //     effectKey: 'beforeAnalysisContent'
      // },
      // {
      //     component: ChatLoadTable,
      //     effectKey: 'analysisIndexList',
      //     componentProps: {
      //         columns: columns2,
      //     }
      // },
      // {
      //     component: ChatLoadText,
      //     effectKey: 'afterAnalysisContent',
      // },
      {
        component: ChatLoadText,
        effectKey: "beforeCalAnalysisContent",
      },
      {
        component: ChatLoadTable,
        effectKey: "list",
        componentProps: {
          columns: columns5,
        },
      },
      {
        component: ChatLoadText,
        effectKey: "afterCalAnalysisContent",
      },
      {
        component: ChatLoadMd,
        effectKey: "analysisReportResult",
      },
    ],
    effectData?.parameterBottleneckResult,
    {
      onLoad: () => {
        onRender && onRender(true);
      },
      onEnd: () => {
        onRender && onRender(true);
        onLoad && onLoad();
      },
    },
    {
      loading: loading,
      autoRender: true,
    },
    {
      onRender,
    }
  );
  return <div className="chat-para-model-calc">{loadedComponents}</div>;
};

export default memo(ChatParaModelCalculate);
